/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.action.account;

import apus.action.Action;
import apus.action.ActionResult;
import apus.entity.Account;
import apus.persistence.AccountDAO;
import apus.persistence.jdbc.DataBaseStatistics;
import apus.services.ServiceLocator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 21vek
 */
public class AccountCreateMonthly implements Action{

    @Override
    public String getName() {
        return "account.monthly";
    }

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        int start = DataBaseStatistics.getStatistics().get("Accounts");
        ServiceLocator.getService(AccountDAO.class).addMonthlyAccounts();
        int count = DataBaseStatistics.getStatistics().get("Accounts") - start;
        if (count>0) {
        request.getSession().setAttribute("win", count +" accounts successfully created");
        } else {
            request.getSession().setAttribute("win", "All accounts have been already created");
        }
        List<Account> accountList = ServiceLocator.getService(AccountDAO.class).findAll();
        request.setAttribute("accountList", accountList);
        return ActionResult.redirect("account.list");
    }
    
}
